package link.jfire.socket.socketserver.handler.impl;

import java.nio.charset.Charset;
import javax.annotation.Resource;
import link.jfire.baseutil.collection.ByteCache;
import link.jfire.baseutil.simplelog.ConsoleLogFactory;
import link.jfire.baseutil.simplelog.Logger;
import link.jfire.socket.socketserver.bus.BusinessCommand;
import link.jfire.socket.socketserver.handler.EntryHandler;
import link.jfire.socket.socketserver.storage.Entry;

@Resource
public class Utf8EchoHandler implements EntryHandler
{
    private Logger  logger  = ConsoleLogFactory.getLogger();
    private Charset charset = Charset.forName("utf-8");
    
    @Override
    public byte interestedDataPacketType()
    {
        return BusinessCommand.ECHO;
    }
    
    @Override
    public void handler(Entry entry)
    {
        ByteCache cache = entry.getBusinessData();
        logger.trace("收到的消息是{},消息长度{}", cache.toString(charset), cache.startRead(0).remaining());
    }
}
